
package edu.asu.bmi.sharp2b.logic;

import java.util.HashMap;

public class PrimitiveManager {
    private final int TOTAL_NUMBER_OF_PRIMITIVES = 3;
    private HashMap prims = new HashMap(TOTAL_NUMBER_OF_PRIMITIVES);
    
    public PrimitiveManager(){
        buildPrims();
    }
    
    public String[] getAllPrimitives(){
        String[] patterns = new String[TOTAL_NUMBER_OF_PRIMITIVES];
        int i = 0;
        for (Object curobj: prims.keySet()){
            String curprim = (String) curobj;
            patterns[i] = curprim;
            i++;
        }
        return patterns;
    }
    
    public String[] finishPartial(String fragment){
        String[] results = new String[TOTAL_NUMBER_OF_PRIMITIVES];
        int i = 0;
        for (Object curobj: prims.keySet()){
            String curprim = (String) curobj;
            if (curprim.startsWith(fragment)){
                results[i] = curprim;
                i++;
            }
        }
        return results;
    }
    
    public PrimitiveFactory getFactory(String pattern){
        return (PrimitiveFactory) prims.get(pattern);
        
    }
    
    private void buildPrims(){
        prims.clear();
        prims.put(SimpleLabComparisonPrimitive.pattern, new LabComparisonFactory());
        prims.put(SimpleLabTimeCheckPrimitive.pattern, new LabTimeCheckFactory());
        prims.put(PtMedStateMedPrimitive.pattern, new PtMedStateMedFactory());
    }
}
